package com.example.demo.service;

import com.example.demo.mapper.EmptyClassRoomDao;
import com.example.demo.mapper.ManagerDao;
import com.example.demo.domain.dao.HbutEmptyClassRoom;
import com.example.demo.domain.receive.EmptyClassRoomReceive;
import com.example.demo.domain.result.EmptyClassRoomResult;
import com.example.demo.domain.result.helper.EmptyClassRoomTime;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.List;

/**
 * @author lizijian
 */
@Service
@Slf4j
public class EmptyClassRoomService {


    @Autowired
    private EmptyClassRoomDao emptyClassRoomDao;

    @Autowired
    private ManagerDao managerDao;



    public void addEmptyClassRoom(ArrayList<HbutEmptyClassRoom> hbutEmptyClassRooms){
        emptyClassRoomDao.addEmptyClassRoom(hbutEmptyClassRooms);
    }

    public void deleteEmptyClassRoom(){
        emptyClassRoomDao.deleteEmptyClassRoom();
    }




    public List<EmptyClassRoomResult> getEmptyClassRoom(Integer [] buildingId,Integer[] week,Integer[] day,Integer[] lesson){
        ArrayList<EmptyClassRoomReceive> emptyClassRoomReceives =new ArrayList<>(100);
        for (Integer b : buildingId) {
            for (Integer w : week) {
                for (Integer d : day) {
                    for (Integer l : lesson) {
                        emptyClassRoomReceives.add(new EmptyClassRoomReceive(b,w,d,l));
                    }
                }
            }
        }
        ArrayList<EmptyClassRoomResult> results=new ArrayList<>(100);
        for (EmptyClassRoomReceive item : emptyClassRoomReceives) {
            List<HbutEmptyClassRoom> emptyClassRoom = emptyClassRoomDao.getEmptyClassRoom(item.getBuildingId(), item.getWeek(), item.getDay(), item.getLesson());
            for (HbutEmptyClassRoom hbutEmptyClassRoom : emptyClassRoom) {
                boolean exist=false;
                for (EmptyClassRoomResult result : results) {
                    if(result.getName().equals(hbutEmptyClassRoom.getClassroom())){
                        exist=true;
                        result.getTimes().add(new EmptyClassRoomTime(item.getBuildingId()+"教", item.getWeek(), item.getDay(), item.getLesson()));
                    }
                }
                if(!exist){
                    ArrayList<EmptyClassRoomTime> times=new ArrayList<>(5);
                    times.add(new EmptyClassRoomTime(item.getBuildingId()+"教", item.getWeek(), item.getDay(), item.getLesson()));
                    results.add(new EmptyClassRoomResult(hbutEmptyClassRoom.getClassroom(),times));
                }
            }
        }
        System.out.println(results.size());
        return results;
    }






}
